import { RoleEnum } from '@/role'
import { stores } from '@/stores'
import { useState } from 'react'
import type { TrainTabProps } from './interface'

export const useTabs = (props: { defaultTab: string }) => {
    const ALL_TAB: TrainTabProps[] = [
        {
            label: '派遣任务',
            value: 'task',
            role: [RoleEnum.teacher, RoleEnum.tutor],
        },
        {
            label: '班级管理',
            value: 'classManage',
            role: [
                RoleEnum.center,
                RoleEnum.province,
                RoleEnum.city,
                RoleEnum.company,
                RoleEnum.teacher,
                RoleEnum.tutor,
            ],
        },
        {
            label: '培训计划',
            value: 'trainPlan',
            role: [RoleEnum.center, RoleEnum.province, RoleEnum.city],
        },
        {
            label: '师资派遣',
            value: 'dispatch',
            role: [RoleEnum.center, RoleEnum.tutor],
        },
        {
            label: '开班审核',
            value: 'classAudit',
            role: [RoleEnum.province, RoleEnum.city],
        },
    ]

    /** 获取当前角色的TAB数组 */
    const tabs = ALL_TAB.filter(item =>
        item.role.includes(stores.userStore.getRoleInfo?.role_id ?? 0),
    )

    /** 当前选中TAB */
    const [activeTab, setActiveTab] = useState<string>(
        props.defaultTab ?? (tabs.length > 0 ? tabs[0].value : ''),
    )

    return [tabs, activeTab, setActiveTab] as [
        tabs: TrainTabProps[],
        active: string,
        setActiveTab: React.Dispatch<React.SetStateAction<string>>,
    ]
}
